package com.example.administrator.x3picturetransliteration.Util.Payment;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;

import com.alipay.sdk.app.PayTask;

import java.util.Map;

/**
 * 支付宝支付
 * Created by Administrator on 2018/7/18.
 */

public class AlipayUtil{

    private Activity activity;
    private Handler mHandler;

    public AlipayUtil(Activity activity,Handler mHandler){
       this.activity=activity;
       this.mHandler=mHandler;
    }

    //发起支付请求
    public void Payment(String info, final int SDK_PAY_FLAG){

        final String orderInfo = info;   // 订单信息

        Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                PayTask alipay = new PayTask(activity);
                Map<String, String> result = alipay.payV2(orderInfo,true);

                Message msg = new Message();
                msg.what = SDK_PAY_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };
        // 必须异步调用
        Thread payThread = new Thread(payRunnable);
        payThread.start();

    }


}
